﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"
#include "GnufInfo.h"
#include "GnufTextControl.h"

namespace gnuf {
    class QtLabel;
    class Color;

    enum class GnufLabelStyle
    {
        eTagLabel,
        eFramelessLabel,
        eIconLabel // 显示图标无文字模式
    };

    class GNUF_BASE_EXPORT Label final
        : public ItemWith<QtLabel>
    {
        CANNOT_COPY_OR_ASSIGN(Label);
    public:
        static const EItemType Type;
        explicit Label(Item *);
        virtual ~Label();

        void setText(const std::wstring& text);
        const std::wstring& text() const;

        void enableTooltip(bool val) { m_enableTooltip = val; }
        bool isEnableTooltip() const { return m_enableTooltip; }

        void setIcon(gcmp::OwnerPtr<Icon>&& icon);
        const Icon* gnuf::Label::icon() const { return m_icon.get(); };

        void setStyle(const GnufLabelStyle& style);
        GnufLabelStyle getStyle() const { return m_style; }

        void setWordWrap(bool on);
        bool wordWrap() { return m_workwrap; }

        void setTextColor(gcmp::OwnerPtr<gnuf::Color>&&);
        const gnuf::Color* textColor() const;

        void setMaximumWidth(int width);
        inline int maximumWidth() const { return m_maximumWidth; }

    protected:
        virtual QtItem* getQtItem() const override;
        // Inherits from ItemWith...
        virtual void onDisconnectFromMyQtItem() override;
        //virtual void onPostInfoChanged() override;
        virtual void onPostVisibilityChanged() override;
        virtual void onPostAbilityChanged() override;
        virtual void onPostAppearanceSettingChanged() override;
        //virtual void onPostBadgeVisibilityChanged() override;
        virtual void onTableRowSelectionChanged(bool bSelected) override;

    private:
        gcmp::OwnerPtr<Info> m_info;
        bool m_enableTooltip;
        bool m_workwrap;
        GnufLabelStyle m_style;
        gcmp::OwnerPtr<gnuf::Color> m_TextColor = nullptr;
        gcmp::OwnerPtr<Icon> m_icon = nullptr;
        int m_maximumWidth = -1;
    };
    
}
